import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_ys7/flutter_ys7.dart';
import "package:get/get.dart";

import '../../../../common/my_icon.dart';
import '../../../../common/style.dart';
import '../../../../config/global_config.dart';
import '../../../../pages/Lift/lift_details/ctrl/video_ctrl.dart';
import '../../../../utils/screenutil/fit.dart';
import '../ctrl/lift_details_ctrl.dart';

class VideoStream extends StatelessWidget {
  final _vc = Get.find<VideoCtrl>();
  final _ldc = Get.find<LiftDetailsCtrl>();

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => Stack(
        children: [
          Container(
            child: Column(
              children: [
                Container(
                  width: 640.f,
                  height: 340.f,
                  color: Colors.black12,
                  child: Ys7VideoView(),
                ),
                Container(
                  color: Colors.white,
                  child: Row(
                    children: [
                      Expanded(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            iconButtons(
                              MyIcon.refresh,
                              cb: () => _vc.refreshVideoStream(),
                            ),
                          ],
                        ),
                      ),
                      verticalBar(),
                      Expanded(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            iconButtons(
                              MyIcon.mkf,
                              color: _vc.microphone.value
                                  ? GlobalConfig.theme
                                  : GlobalConfig.assistColor,
                              cb: () => _vc.changeMicrophone(),
                            ),
                          ],
                        ),
                      ),
                      verticalBar(),
                      Expanded(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            iconButtons(
                              _vc.volume.value ? MyIcon.yl : MyIcon.gbyl,
                              color: _vc.volume.value
                                  ? GlobalConfig.theme
                                  : GlobalConfig.assistColor,
                              cb: () => _vc.changeVolume(),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
          _vc.viodeConnectComplete.value
              ? SizedBox.shrink()
              : Positioned(
                  child: Container(
                    width: 640.f,
                    height: 340.f,
                    color: Colors.black,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        SpinKitFadingCircle(
                          color: Colors.white,
                          size: 60.f,
                        ),
                        SizedBox(height: 10),
                        Text(
                          "视频连接中...",
                          style: TextStyle(color: Colors.white, fontSize: 24.f),
                        ),
                      ],
                    ),
                  ),
                ),
          !_ldc.viodeConnectfail.value
              ? SizedBox.shrink()
              : Positioned(
                  child: Container(
                    width: 640.f,
                    height: 340.f,
                    color: Colors.black,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Icon(MyIcon.cuowu, size: 100.f, color: Colors.white),
                        SizedBox(height: 10),
                        Text(
                          "视频加载失败...",
                          style: TextStyle(color: Colors.white, fontSize: 24.f),
                        ),
                      ],
                    ),
                  ),
                ),
        ],
      ),
    );
  }

  /// 创建icon按钮
  /// * [icon] IconData|icons图标|必填
  /// * [cb] Function|回调函数|选填
  /// * [color] Color|icon颜色|选填
  Widget iconButtons(IconData icon, {Function cb, Color color = Colors.black}) {
    return IconButton(
      splashColor: Colors.transparent,
      icon: Icon(icon, size: 35.f, color: color),
      onPressed: () => cb(),
    );
  }

  /// 创建竖线
  Widget verticalBar() {
    return SizedBox(
      width: 1,
      height: 40.f,
      child: Container(
        decoration: BoxDecoration(
          gradient: Style.gradient,
        ),
      ),
    );
  }
}
